//
//  BaseViewController.swift
//  weibo
//
//  Created by wang_h on 2017/5/25.
//  Copyright © 2017年 wang_h. All rights reserved.
//

import UIKit

class BaseViewController: UITableViewController {
    
    lazy var visitorView : VisitorView = VisitorView.visitorView()
    
    var isLogin : Bool = UserAccountViewModel.shareInstance.isLogin

    override func loadView() {
        isLogin ? super.loadView() : setupVistorView()
    }
    override func viewDidLoad() {
        super.viewDidLoad()
    }
}
//MARK:- 设置UI界面
extension BaseViewController {
    //设置访客视图
    func setupVistorView() {
        view = visitorView
        visitorView.registerBtn.addTarget(self, action: #selector(registerBtnClick), for: .touchUpInside)
        visitorView.loginBtn.addTarget(self, action: #selector(loginBtnClick), for: .touchUpInside)
        setupNavigationItems()
    }
    //设置导航栏左右的item
    func setupNavigationItems() {
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .plain, target: self, action: #selector(registerBtnClick))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .plain, target: self, action: #selector(loginBtnClick))
    }
}
//MARK:- 事件监听
extension BaseViewController{
    
    func registerBtnClick() {
        print("registerBtnClick")
    }
    func loginBtnClick() {
        //1.创建授权控制器
        let oauthVC = OAuthViewController()
        //2.包装导航栏控制器
        let oauthNav = UINavigationController(rootViewController: oauthVC)
        //3.弹出控制器
        present(oauthNav, animated: true, completion: nil)
    }
}
